From 36a4013adf2e5cc0fa428099a5a2eac28cf3abae Mon Sep 17 00:00:00 2001 From: robertlipe Date: Thu, 25 Jul 2013 20:43:47 +0000 Subject: [PATCH] Whittle away at more implicit time_t conversions. In some cases, I'm just moving the problem around, but these are all relatively obscure formats anyway and pre-1970 times aren't that important for them anyway. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4476 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/arcdist.cc | 4 ++-- gpsbabel/compegps.cc | 4 +++- gpsbabel/destinator.cc | 4 ++-- gpsbabel/exif.cc | 2 +- gpsbabel/geoniche.cc | 6 +++++- gpsbabel/gpssim.cc | 4 ++-- gpsbabel/humminbird.cc | 2 +- gpsbabel/igo8.cc | 6 +++--- gpsbabel/jtr.cc | 2 +- gpsbabel/navilink.cc | 4 ++-- gpsbabel/pathaway.cc | 4 ++-- gpsbabel/route.cc | 6 +++--- gpsbabel/src/core/datetime.h | 10 ---------- gpsbabel/xol.cc | 4 ++-- 14 files changed, 29 insertions(+), 33 deletions(-) diff --git a/gpsbabel/arcdist.cc b/gpsbabel/arcdist.cc index 60239360e..945f29f5b 100644 --- a/gpsbabel/arcdist.cc +++ b/gpsbabel/arcdist.cc @@ -230,8 +230,8 @@ arcdist_process(void) } } if (trkopt && - (ed->arcpt2->creation_time != 0) && - (ptsopt || (ed->arcpt1->creation_time != 0))) { + (ed->arcpt2->GetCreationTime().isValid()) && + (ptsopt || (ed->arcpt1->GetCreationTime().isValid()))) { /* Interpolate time */ if (ptsopt) { wp->creation_time = ed->arcpt2->creation_time; diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index 9a8251b0b..a0e46f2d8 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -561,7 +561,9 @@ write_trkpt_cb(const waypoint* wpt) buff[0] = '\0'; - if (wpt->creation_time != 0) { +// TOOD: This should probably attempt a gmtime and then fall back to the 1-1-1970 +// case or bypass the time_t completely and build string representations directly. + if (wpt->creation_time.isValid()) { const time_t tt = wpt->GetCreationTime(); struct tm tm = *gmtime(&tt); diff --git a/gpsbabel/destinator.cc b/gpsbabel/destinator.cc index e7c77d2f0..3543fe3a3 100644 --- a/gpsbabel/destinator.cc +++ b/gpsbabel/destinator.cc @@ -433,11 +433,11 @@ destinator_trkpt_disp(const waypoint* wpt) gbfputint32(0, fout); } - if (wpt->creation_time) { + if (wpt->creation_time.isValid()) { struct tm tm; double milliseconds; int date; - const time_t ct = wpt->GetCreationTime(); + const time_t ct = wpt->GetCreationTime().toTime_t(); tm = *gmtime(&ct); tm.tm_mon += 1; tm.tm_year -= 100; diff --git a/gpsbabel/exif.cc b/gpsbabel/exif.cc index 73450a9d0..377b7144b 100644 --- a/gpsbabel/exif.cc +++ b/gpsbabel/exif.cc @@ -1106,7 +1106,7 @@ exif_remove_tag(const int ifd_nr, const int tag_id) static void exif_find_wpt_by_time(const waypoint* wpt) { - if (wpt->creation_time <= 0) { + if (!wpt->creation_time.isValid()) { return; } diff --git a/gpsbabel/geoniche.cc b/gpsbabel/geoniche.cc index 35a90eb3c..2c9f4610b 100644 --- a/gpsbabel/geoniche.cc +++ b/gpsbabel/geoniche.cc @@ -746,7 +746,11 @@ geoniche_writewpt(const waypoint* wpt) id = rec_ct; } - tx = (wpt->GetCreationTime() != 0) ? wpt->GetCreationTime() : gpsbabel_time; + if (wpt->GetCreationTime().isValid()) { + tx = wpt->GetCreationTime().toTime_t(); + } else { + tx = gpsbabel_time; + } if (tx == 0) { /* maybe zero during testo (freezed time) */ strcpy(datestr, "01/01/1904"); /* this seems to be the uninitialized date value for geoniche */ strcpy(timestr, "00:00:00"); diff --git a/gpsbabel/gpssim.cc b/gpsbabel/gpssim.cc index abf9728e7..87976811c 100644 --- a/gpsbabel/gpssim.cc +++ b/gpsbabel/gpssim.cc @@ -121,12 +121,12 @@ gpssim_write_pt(const waypoint* wpt) wpt->altitude == unknown_alt ? 0 : wpt->altitude ); - if (wpt->creation_time) { + if (wpt->creation_time.isValid()) { char tbuf[20]; int hms, ymd; struct tm* tm; - const time_t tt = wpt->GetCreationTime(); + const time_t tt = wpt->GetCreationTime().toTime_t(); tm = gmtime(&tt); hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 88bc0ae34..bc6fa67fe 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -781,7 +781,7 @@ humminbird_track_cb(const waypoint* wpt) lat = geodetic_to_geocentric_hwr(wpt->latitude); north = si_round(inverse_gudermannian_i1924(lat)); - if (wpt->creation_time != 0) { + if (wpt->creation_time.isValid()) { last_time = wpt->GetCreationTime(); } diff --git a/gpsbabel/igo8.cc b/gpsbabel/igo8.cc index 726830bdc..6c77e37d4 100644 --- a/gpsbabel/igo8.cc +++ b/gpsbabel/igo8.cc @@ -216,10 +216,10 @@ static void write_igo8_track_point(const waypoint* wpt) // iGo8 appears to expect a time, if one isn't provided // then we shall make our own, where each point is one // second apart. - if (wpt->creation_time == 0) { - le_write32(&point.unix_time, invented_time++); - } else { + if (wpt->creation_time.isValid()) { le_write32(&point.unix_time, wpt->GetCreationTime()); + } else { + le_write32(&point.unix_time, invented_time++); } // Write the first part of the Information Block, the start time diff --git a/gpsbabel/jtr.cc b/gpsbabel/jtr.cc index b4ec4d8d8..adfc12b62 100644 --- a/gpsbabel/jtr.cc +++ b/gpsbabel/jtr.cc @@ -273,7 +273,7 @@ jtr_trkpt_disp_cb(const waypoint* wpt) char stime[10], sdate[7], scourse[6], sspeed[8]; struct tm tm; - if (wpt->creation_time > 0) { + if (wpt->creation_time.isValid()) { const time_t tt = wpt->GetCreationTime(); tm = *gmtime(&tt); diff --git a/gpsbabel/navilink.cc b/gpsbabel/navilink.cc index 12c6a9557..dcbed7e8d 100644 --- a/gpsbabel/navilink.cc +++ b/gpsbabel/navilink.cc @@ -430,7 +430,7 @@ encode_waypoint(const waypoint* waypt, unsigned char* buffer) buffer[10] = 0; buffer[11] = 0; encode_position(waypt, buffer + 12); - encode_datetime(waypt->GetCreationTime(), buffer + 22); + encode_datetime(waypt->GetCreationTime().toTime_t(), buffer + 22); buffer[28] = find_icon_from_descr(waypt->icon_descr); buffer[29] = 0; buffer[30] = 0x00; @@ -465,7 +465,7 @@ encode_trackpoint(const waypoint* waypt, unsigned serial, unsigned char* buffer) le_write32(buffer + 4, x); le_write32(buffer + 8, y); encode_position(waypt, buffer + 12); - encode_datetime(waypt->GetCreationTime(), buffer + 22); + encode_datetime(waypt->GetCreationTime().toTime_t(), buffer + 22); buffer[28] = z; buffer[29] = MPS_TO_KPH(WAYPT_GET(waypt, speed, 0) / 2); buffer[30] = 0x5a; diff --git a/gpsbabel/pathaway.cc b/gpsbabel/pathaway.cc index 432d645c6..16a08ecac 100644 --- a/gpsbabel/pathaway.cc +++ b/gpsbabel/pathaway.cc @@ -689,9 +689,9 @@ static void ppdb_write_wpt(const waypoint *wpt) buff = ppdb_strcat(buff, ",", NULL, &len); /* 4 time, date */ - if (wpt->creation_time != 0) { + if (wpt->creation_time.isValid()) { tmp = str_pool_get(20); - const time_t tt = wpt->GetCreationTime(); + const time_t tt = wpt->GetCreationTime().toTime_t(); tm = *gmtime(&tt); strftime(tmp, 20, datefmt, &tm); buff = ppdb_strcat(buff, tmp, NULL, &len); diff --git a/gpsbabel/route.cc b/gpsbabel/route.cc index a0c106bd8..1e5b7e7bf 100644 --- a/gpsbabel/route.cc +++ b/gpsbabel/route.cc @@ -570,9 +570,9 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) *trkdatap = tdata; } - first.latitude = 0; - first.longitude = 0; - first.creation_time = 0; +// first.latitude = 0; +// first.longitude = 0; +// first.creation_time = 0; tdata->min_hrt = 9999; tdata->min_alt = -unknown_alt; tdata->max_alt = unknown_alt; diff --git a/gpsbabel/src/core/datetime.h b/gpsbabel/src/core/datetime.h index b6ca697b6..2e0f97f4e 100644 --- a/gpsbabel/src/core/datetime.h +++ b/gpsbabel/src/core/datetime.h @@ -54,16 +54,6 @@ public: return t; } - time_t operator--(int) { - setTime_t(toTime_t() - 1); - return toTime_t(); - } - - time_t operator++(int) { - setTime_t(toTime_t() + 1); - return toTime_t(); - } - time_t operator+=(const time_t& t) { setTime_t(toTime_t() + t); return toTime_t(); diff --git a/gpsbabel/xol.cc b/gpsbabel/xol.cc index e6827716b..ff8418b3b 100644 --- a/gpsbabel/xol.cc +++ b/gpsbabel/xol.cc @@ -267,7 +267,7 @@ xol_waypt_disp_cb(const waypoint *wpt) xol_write_string("name", name); xol_write_string("comment", wpt->notes); xol_write_string("icon", wpt->icon_descr.toUtf8().data()); - if (wpt->creation_time) { + if (wpt->creation_time.isValid()) { xol_write_time(wpt); } if (wpt->altitude != unknown_alt) { @@ -309,7 +309,7 @@ xol_trkpt_disp_cb(const waypoint *wpt) } gbfprintf(fout, "%*screation_time) { + if (wpt->creation_time.isValid()) { xol_write_time(wpt); } if (wpt->altitude != unknown_alt) { -- 2.30.2